package com.itheima.web.controller;

import cn.hutool.core.util.StrUtil;
import com.itheima.web.manager.UserManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired
    private UserManager userManager;

    // 用户列表
    @GetMapping("/manage/users")
    public ResponseEntity findUserByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        // 调用manager
        return userManager.findUserByPage(pageNum, pageSize);
    }

    // 用户详情
    @GetMapping("/manage/users/{userID}")
    public ResponseEntity findUserInfoById(@PathVariable Long userID) {
        // 调用manager
        return userManager.findUserInfoById(userID);
    }

    // 动态列表
    @GetMapping("/manage/messages")
    public ResponseEntity findMovementVoByPage(
            Long uid,
            String state,
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {

        // 处理审核状态
        Integer stateInt = null;
        if (StrUtil.isNotEmpty(state) && !state.equals("''")) {
            stateInt = Integer.parseInt(state);
        }

        // 调用manager
        return userManager.findMovementVoByPage(uid, stateInt, pageNum, pageSize);
    }

    // 动态详情
    @GetMapping("/manage/messages/{movementId}")
    public ResponseEntity findMovementVoById(@PathVariable String movementId) {
        // 调用manager
        return userManager.findMovementVoById(movementId);
    }

    // 动态评论列表
    @GetMapping("/manage/messages/comments")
    public ResponseEntity findMovementComemntByPage(
            @RequestParam("messageID") String movementId ,
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize){
        // 调用manager
        return userManager.findMovementComemntByPage(movementId,pageNum,pageSize);
    }

    // 视频列表
    @GetMapping("/manage/videos")
    public ResponseEntity findVideoVoByPage(
            Long uid,
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize){
        // 调用manager
        return userManager.findVideoVoByPage(uid,pageNum,pageSize);
    }

}
